﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DAL;
using BLL;
using BOL;
using DevComponents.DotNetBar;
using DevComponents.AdvTree;

namespace QuanLyHangXeKhach
{
    public partial class frmTraCuuDatVe : UserControl
    {
        TraCuuThongTinDatVe ttdv = new TraCuuThongTinDatVe();
        DieuKhien dk = new DieuKhien();
        public frmTraCuuDatVe()
        {
            InitializeComponent();
        }

        #region Điều khiển đóng/mở form
        private DieuKhien _Commands;
        /// <summary>
        /// Gets or sets the commands associated with the control.
        /// </summary>
        public DieuKhien Commands
        {
            get { return _Commands; }
            set
            {
                if (value != _Commands)
                {
                    DieuKhien oldValue = _Commands;
                    _Commands = value;
                    OnCommandsChanged(oldValue, value);
                }
            }
        }
        /// <summary>
        /// Called when Commands property has changed.
        /// </summary>
        /// <param name="oldValue">Old property value</param>
        /// <param name="newValue">New property value</param>
        protected virtual void OnCommandsChanged(DieuKhien oldValue, DieuKhien newValue)
        {
            if (newValue != null)
            {
                btndong.Command = newValue.dongfrmdatve;               
            }
            else
            {
                btndong.Command = null;                
            }
        }

        #endregion

        private void buttonX1_Click(object sender, EventArgs e)
        {

            List<thongtindatve> thongtin = ttdv.laythongtinve(txtmave.Text.Trim());
            if (thongtin.Count == 0)
            {
                MessageBoxEx.Show("Không có thông tin về vé " + txtmave.Text + "", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                xoatrang();
            }
            else
            {
                foreach (var row in thongtin)
                {
                    lbltenkh.Text = row.tenkh;
                    lbldiachi.Text = row.diachi;
                    lblsdt.Text = row.sodt;
                    lbltuyenduong.Text = row.tuyenduong;
                    lbltenxe.Text = row.tenxe;
                    lblbienso.Text = row.bienso;
                    lblsochongoi.Text = row.sochongoi;
                    lblghedat.Text = row.ghedat;
                    lblgiodi.Text = row.giodi + "h " + row.ngaydi;
                    lblgiochay.Text = row.thoigianxechay;
                    lbldiemdung.Text = row.diemdung;
                    lblnhanvien.Text = row.nhanvien;
                    lblgiave.Text = String.Format("{0:0,0 vnđ}", int.Parse(row.giave));
                    lblngaylap.Text = row.ngaylap;
                }
            }
        }

        public void xoatrang()
        {
            lbltenkh.Text = "-----------";
            lbldiachi.Text = "-----------";
            lblsdt.Text = "-----------";
            lbltuyenduong.Text = "-----------";
            lbltenxe.Text = "-----------";
            lblbienso.Text = "-----------";
            lblsochongoi.Text = "-----------";
            lblghedat.Text = "-----------";
            lblgiodi.Text = "-----------";
            lblgiochay.Text = "-----------";
            lbldiemdung.Text = "-----------";
            lblnhanvien.Text = "-----------";
            lblgiave.Text = "-----------";
            lblngaylap.Text = "-----------";
        }

        private void panelEx1_Click(object sender, EventArgs e)
        {
           
        }

        private void frmTraCuuDatVe_Load(object sender, EventArgs e)
        {
            xoatrang();
        }
    }
}
